package commands

import (
	"github.com/urfave/cli"

	"../flags"
	"../utils"
)

// Fresh - pull and push
func Fresh(config utils.Config) cli.Command {
	return cli.Command{
		Name:     "fresh",
		Usage:    "pull and push",
		Category: "COMMON COMMANDS",
		Flags: []cli.Flag{
			flags.Flags["path"],
			flags.Flags["message"],
		},
		Action: makeAction(config, freshAction),
	}
}

func freshAction(conf utils.Config, git utils.Git, context *cli.Context) error {
	/*
		result, err := utils.LoadConfig(conf, git, "config")
		if err != nil {
			return err
		}
		var username string
		username, err = result.String("session", conf.PcCode)
		if err != nil {
			return errors.New("The Project based in sgbm, please login to fresh")
		}

		message := context.String("message")

		_, err = git.Execute(
			[]string{"pull", "--all"},
			[]string{"add", "."},
			[]string{"commit", "-m", "push by " + username + "&" + message},
			[]string{"push", "-u", "origin", "--all"},
			[]string{"push", "-u", "origin", "--tags"},
		)
		return err
	*/
	message := context.String("message")

	_, err := git.Execute(
		[]string{"pull", "--all"},
		[]string{"add", "."},
		[]string{"commit", "-m", message},
		[]string{"push", "-u", "origin", "--all"},
		[]string{"push", "-u", "origin", "--tags"},
	)
	return err
}
